package cn.edu.scau.cmi.zhangjunming.client;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import cn.edu.scau.cmi.zhangjunming.spring.domain.Student;
import cn.edu.scau.cmi.zhangjunming.spring.onlySpring.ApplicationContextUtil;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

public class SpringClient extends Application{

	public static void main(String[] args) {
		launch(args);
	}
	
	public SpringClient() {
		
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO 自动生成的方法存根
		
		TextArea textArea = new TextArea();
		textArea.setPrefWidth(600);
		textArea.setPrefHeight(400);
		textArea.setLayoutX(10);
		textArea.setLayoutY(80);
		
		Button getButton = new Button("获取对象");
		getButton.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent arg0) {
				//ApplicationContexUtil ac = new ApplicationContexUtil();
				BeanFactory applicationContext = ApplicationContextUtil.getApplicationContext();
				Student student = (Student) applicationContext.getBean("zhangsan");
				textArea.clear();
				textArea.appendText(student.getName()+" 的毕业导师是："+student.getTutor().getName());
			}
		});
		getButton.setLayoutX(240);
		getButton.setLayoutY(40);
		
		Group group = new Group(textArea,getButton);
		Scene scene = new Scene(group,620,550);
		
		primaryStage.setTitle("Spring框架使用");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

}
